<template>
  <div>
    <el-table
        :data="fileListData"
        border
        style="width: 100%">
      <el-table-column
          :label="main.order"
          width="60"
          align="center"
          v-slot:default="scope">
        {{scope.$index+1}}
      </el-table-column>
      <el-table-column
          prop="fileName"
          :label="main.fileName"
          align="center"
          v-slot:default="scope">
        <span v-if="scope.row.fileName==='' || scope.row.fileName===undefined || scope.row.fileName===null"></span>
        <span v-else-if="scope.row.fileName.split('-').length>=1 && scope.row.fileName.split('-')[0].length===32">{{scope.row.fileName.slice(33)}}</span>
        <span v-else>{{scope.row.fileName}}</span>
      </el-table-column>
      <el-table-column
          :label="main.operate"
          v-slot:default="scope"
          align="center"
          width="90">
        <el-link @click="viewFile(scope)">
          <i class="el-icon-view" style="font-size: 18px"></i>
        </el-link>
        <el-link @click="downloadFile(scope)" style="margin-left: 10px">
          <i class="el-icon-download" style="font-size: 18px"></i>
        </el-link>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import {Util_Download_File} from "@/components/utils/useUtils";

export default {
  name: "viewFileList",
  props: {
    // 正确写法：指定 type
    languageS: {
      type: String,  // 必须是构造函数
      default: 'chinese'    // 默认值可选
    },
    tableParent: {
      type: Array,
      default: () => [
        {fileName:''}
      ] // 默认值应该是函数返回空数组
    }
  },
  data(){
    return{
      fileListData:this.tableParent,
      main:{
        order:'序号',
        fileName:'文件名称',
        operate:'操作'
      },
    }
  },
  methods:{
    changeLanguage(language){
      // 其他语言切换逻辑...
      this.componentKey = !this.componentKey;
      if (language==='chinese'){
        this.main.order='序号'
        this.main.fileName='文件名称'
        this.main.operate='操作'
      }
      else if (language==='english'){
        this.main.order='Order'
        this.main.fileName='File Name'
        this.main.operate='Operate'
      }
      else if (language==='russian'){
        this.main.order='Заказ'
        this.main.fileName='Имя файла'
        this.main.operate='Операция'
      }
    },
    downloadFile(scope){
      Util_Download_File(scope.row.fileName).then(data=>{
        if (data==="未登录"){
          this.$message.error("Not logged in")
        }
        else if (data==="下载成功"){
          this.$message.success("Download successfully")
        }
        else if (data==="未下载成功"){
          this.$message.error("Download failed")
        }
      })
    },
  },
  mounted() {
    // 初始化语言设置
    this.changeLanguage(this.languageS);
  }
}
</script>

<style scoped>

</style>